//app.js
App({
  //全局变量
  globalData: {
    formids: []
  },
  onLaunch: function () {
    //调用API从本地缓存中获取数据    
  },
  onShow: function () {
  },
  onHide: function () {
  },
  onError: function (msg) {
    console.log(msg)
  },

  kbtools: require('/wdlebroker/static/tools.js'),

  util: require('/we7/resource/js/util.js'),
   
  /**
 * 设置导航栏
 */
  setbottom_bar: function ($this) {
    let that = $this;
    let tabBar = this.indextabBar;
    for (let i in tabBar['list']) {
      tabBar['list'][i]['pageUrl'] = tabBar['list'][i]['pagePath'].replace(/(\?|#)[^"]*/g, '')
    }
    that.setData({
      indexBar: tabBar,
      'indexBar.thisurl': that.__route__
    })
  },
  /**检查是否登录 */
  checkAuthorLogin: function ($this, callback_url, haslogin_callback) {
    const self = $this;
    var app = getApp();
    /**设置回调地址 */
    if (typeof (callback_url) == 'string') {
      wx.setStorage({
        key: "login_callback",
        data: callback_url
      });
    }
    /**判断是否有登录信息 */
    wx.getStorage({
      key: 'userInfo',
      success: function (res) {
        var uid = 0;
        if (!app.kbtools.isnull(res.data.memberInfo)) {
          uid = res.data.memberInfo.uid;
        }
        if (uid) {
          self.setData({ islogin: true });
          if (typeof haslogin_callback == 'function') {
            haslogin_callback();
          }
        } else {
          /**重新登*/
          wx.redirectTo({
            url: '/wdlebroker/pages/user/login'
          })

        }
      },
      fail: function (e) {
        /**重新登*/
        wx.redirectTo({
          url: '/wdlebroker/pages/user/login'
        })

      }
    })
    /**==== */
  },
  /**显示地图导航js 
   * addr = 坐标时直接显示，等于中文地址需要调用接口解析出坐标
   *  addr 中文地址，name=显示的标题*/
  showMapLocation: function (addr, name) {
    var app = getApp();
    if (app.kbtools.isnull(addr)) {
      return false;
    }
    if (addr.indexOf(",") > 0) {
      var point = addr.split(',');
      wx.openLocation({
        latitude: parseFloat(point[1]),
        longitude: parseFloat(point[0]),
        name: name,
        scale: 16
      })

    } else { /**解析地址 换去坐标 */
      app.util.request({
        'url': 'entry/wxapp/mapparse',
        data: { addr: addr },
        success(res) {
          if (!app.kbtools.isnull(res.data.data.result)) {
            wx.openLocation({
              latitude: parseFloat(res.data.data.result[1]),
              longitude: parseFloat(res.data.data.result[0]),
              name: name,
              scale: 16
            })
          }
        }
      });
    }
    /** */
  },
  //用户信息，sessionid是用户是否登录的凭证
  userInfo: {
    sessionid: null // 无需修改
  },

  //站点信息
  siteInfo: require('siteinfo.js')

});
